package com.saint.farmshop.Mapper.MapperImpl;

import com.saint.farmshop.Entity.ProductionSecondType;
import com.saint.farmshop.Mapper.ProductionSecondTypeMapper;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * 产品二级分类映射器实现类
 *
 * @author Saint
 * @date 2022/05/22
 */
@Repository
public class ProductionSecondTypeMapperImpl implements ProductionSecondTypeMapper {

    @Resource
    MongoTemplate mongoTemplate;

    final String COLLECTION_NAME = "second_type_list";

    @Override
    public List<ProductionSecondType> getSecondTypeListById(String typeId) {
        Criteria criteria = new Criteria();
        criteria.and("typeId").is(typeId);
        Query query = new Query(criteria);
        List<ProductionSecondType> productionSecondTypes = mongoTemplate.find(query, ProductionSecondType.class, COLLECTION_NAME);
        return productionSecondTypes;
    }
}
